<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!--#include file="DoAction.aspx"-->
<script  runat="server">
Dim TotalRecords=0,TotalPages=0
Dim Records=10
Sub Page_Load(ByVal sender As Object, _
	ByVal e As EventArgs)
	If Not Page.IsPostBack Then			
		BindGrid()
        	End If
	TotalPages=DataResult.PageCount	
	doDelete()
End Sub
Sub MyDataGridPage(sender As Object, e As _
	DataGridPageChangedEventArgs) 
	DataResult.CurrentPageIndex = e.NewPageIndex		
	BindGrid	
End Sub
Private Sub BindGrid()		
	DataResult.PageSize=Records		 
	Dim strSQL = "select * from tblCategories"
	Dim myConnection As SqlConnection = _
	New SqlConnection(ConfigurationSettings.appSettings("conn"))	
	dim myAdapter as SqlDataAdapter = _
	New SqlDataAdapter(strSQL, myConnection)
	dim myDataSet as DataSet = New DataSet()		
	myAdapter.Fill(myDataSet,strSQL)
	TotalRecords=myDataSet.Tables(strSQL).Rows().Count
	if TotalRecords >Records  then
		DataResult.AllowPaging="True"
	else
		DataResult.AllowPaging="False"
	end if		
	DataResult.DataSource=myDataSet
	DataResult.DataBind()
End Sub

Sub doDelete() 
	Dim strID as String=Request.form("chkid")
	If strID  <>"" then
	strID="Delete from tblCategories" & _
		" Where CateID in (" + strID + ")"		
		if Not doSQL(strID) then
			Response.Write("Can not delete")
		end if
	End If
End Sub
</script>
<html>
<head>
<title>DataGrid Control</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<h2>DataGrid and Delete</h2>
<form runat=server >
                   <table width="100%" border="0" cellpadding="0" cellspacing="0">
                      <tr> 
                        <td >          
                          <asp:DataGrid  
		ID="DataResult"	
		ClientID="dgGrid"	
		AllowSorting="True"
		PagerStyle-Mode="NumericPages"
		PagerStyle-Position ="Bottom"
		PagerStyle-PageButtonCount=2								
		PagerStyle-HorizontalAlign="Right"
		OnPageIndexChanged="MyDataGridPage" 
		BorderColor="#999999"
		BorderWidth="0"
		GridLines="Both"
		CellPadding="0"
		CellSpacing="0"
		Font-Name="Verdana"
		Font-Size="8pt"
		width="100%" 														
		HeaderStyle-CssClass="row_gray"
		BackColor="#FFFFFF"
		ShowHeader="True"
		AutoGenerateColumns="False" runat="server" > <Columns> 
                          	<asp:TemplateColumn HeaderText="CateID"> <ItemTemplate> 
                          	<asp:Label ID="ItemID" Text=<%# DataBinder.Eval(Container.DataItem, "CateID").toString() %> Runat=server /> 
                          	</ItemTemplate> </asp:TemplateColumn>
		<asp:TemplateColumn HeaderText="CateName"> <ItemTemplate> 
                          	<asp:Label ID="ItemName" Text=<%# DataBinder.Eval(Container.DataItem, "CateName").toString() %> Runat=server /> 
                          	</ItemTemplate> </asp:TemplateColumn>
		<asp:TemplateColumn HeaderText="Delete"> 
                                <ItemTemplate> <asp:Label ID="Delete" Text=<%#  "<input type=checkbox name='chkid' id='chkid' value="+ DataBinder.Eval(Container.DataItem, "CateID").toString()+"></a>" %> Runat=server /> 
                                </ItemTemplate> </asp:TemplateColumn> 
		</Columns> </asp:DataGrid> 
                        </td>
                      </tr>
                </table><br />
	<input type=submit value="Delete">
</form>
</body>
</html>
